import {pdsData,jfAndfwData} from '@/api/grzx/grzx.js'
import login from "@/store/login/login.js"
import api from "@/api/config.js"
export default {
  namespaced: true,
  state: () => ({
		pdNum:0,
		score:0,
		joinHours:0
  }),

  // 模块的 mutations 方法
  mutations: {
	  //派单数
		getpds(state,payload){
			 let userId=login.state().userInfo?login.state().userInfo.userId:''
			pdsData(userId).then(res=>{
				state.pdNum=res.data.data.dealCount
				
			})
		},
		//积分和服务时长
		
		getjfAndfw(state,payload){
			 let userId=login.state().userInfo?login.state().userInfo.userId:''
			 let id=login.state().userInfo?login.state().userInfo._id:''
			jfAndfwData(userId,id).then(res=>{
				console.log(res)
				if(res.data.data.statisticInfo){
					let arr=res.data.data.statisticInfo
					arr.forEach((item,index, arr)=>{
						if(item.companyId==api.companyId){
							state.score=item.score
							state.joinHours=item.joinHours
						}
						
					})
					
				
				
				}
				
				
				
			})
		},
		//实践所
		getSjs(state,payload){
			
			 let userId=login.state().userInfo?login.state().userInfo.userId:''
			getSjsData(userId,1).then(res=>{
				
				state.sjsInfo=res.data.data.results
				if(Object.keys(state.sjsInfo).length>0){
					if(payload.success){
						payload.success(res)
					}
				}
			})
		},
		//删除实践所
		clearSjs(state){
			state.sjsInfo=[]
		},
		
		//实践所 弹起展示
		getSjsXl(state,payload){
			 let userId=login.state().userInfo?login.state().userInfo.userId:''
			getSjsXlData(userId).then(res=>{
			
				state.sjsXlInfo=res.data.data
				if(Object.keys(state.sjsXlInfo).length>0){
					if(payload.success){
						payload.success(res)
					}
				}
				
			})
		},
		
		clearSjsXl(state){
			state.sjsXlInfo=[]
		},
		//实践所确定选择
		
		getSjsById(state,payload){
			 let userId=login.state().userInfo?login.state().userInfo.userId:''
			getSjsByIdData(userId,1,payload.id).then(res=>{
				state.sjsByIdInfo=res.data.data.results
				if(payload.success){
					payload.success(res)
				}
				
			})
		},
		
		//删除通过id查询的实践所
		clearSjsById(state){
			state.sjsByIdInfo=[]
		},
		
		
		//实践站
		getSjz(state,payload){
			 let userId=login.state().userInfo?login.state().userInfo.userId:''
			getSjzData(userId,1).then(res=>{
				
				state.sjzInfo=res.data.data.results
				if(Object.keys(state.sjzInfo).length>0){
					if(payload.success){
						payload.success(res)
					}
				}
			})
		},
		clearSjz(state){
			state.sjzInfo=[]
		},
		//实践站下拉框展示getSjzXlData
		getSjzXl(state,payload){
			 let userId=login.state().userInfo?login.state().userInfo.userId:''
			getSjzXlData(userId).then(res=>{
				
				state.sjzXlInfo=res.data.data
				if(Object.keys(state.sjzXlInfo).length>0){
					if(payload.success){
						payload.success(res)
					}
				}
				
			})
		},
		clearSjzXl(state){
			state.sjzXlInfo=[]
		},
		
		//实践站确定选择
		
		getSjzById(state,payload){
			 let userId=login.state().userInfo?login.state().userInfo.userId:''
			getSjzByIdData(userId,1,payload.id).then(res=>{
				state.sjzByIdInfo=res.data.data.results
				
			})
		},
		
		//删除通过id查询的实践站
		clearSjzById(state){
			state.sjzByIdInfo=[]
		},
		
		//获取搜索结果
				getSearch(state,payload){
					 let userId=login.state().userInfo?login.state().userInfo.userId:''
					getSearchData(userId,payload.value,1).then(res=>{
						
						state.searchInfo=res.data.data.results
						if(Object.keys(state.searchInfo).length>0){
							if(payload.success){
								payload.success(res)
							}
						}
					})
				},
		//清除搜索结果
				clearSearch(state,payload){
					state.searchInfo=[]
					
				}
		
  },

  // 模块的 getters 属性
  getters: {
	
  }
}